<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class BrandRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name'         => 'required|string|min:2|max:100',      // 授权书名称
            'expiry_month' => 'required|integer',                   // 有效期
            'need_pay'     => 'required|boolean',                   // 是否需要支付
            'amount'       => 'sometimes|numeric',                  // 支付金额
            'need_verify'  => 'required|boolean',                   // 是否需要审核
            'status'       => 'required|in:0,1,2',                  // 状态：0未启用，1进行中，2已停用
            'callback_url' => 'sometimes',                          // 事件回调地址，如果需要审核或需要支付，必须填写回调地址
            'images'       => 'required|array',

            'fields.*.name'        => 'required|string|min:2|max:100',      // 字段名称
            'fields.*.type'         => 'required|in:text,textarea,datetime', // 字段类型：text,textarea,datetime
            'fields.*.is_required'  => 'required|boolean',                   // 是否必填
            'fields.*.notice'       => 'sometimes|max:100',           // 提示文字

            'images.*.fields.*.field_id'       => 'required',                        //字段ID
            'images.*.fields.*.scale_x'        => 'required|numeric',                //横坐标
            'images.*.fields.*.scale_y'        => 'required|numeric',                //横坐标
            'images.*.fields.*.font_size'      => 'required|numeric',                //字体大小
        ];
    }

    public function attributes()
    {
        return [
            'name'         => '授权书名称',
            'expiry_month' => '有效期',
            'need_pay'     => '是否需要支付',
            'amount'       => '支付金额',
            'need_verify'  => '是否需要审核',
            'status'       => '状态',
            'callback_url' => '事件回调地址',

            'label'        => '字段名称',
            'type'         => '字段类型',
            'is_required'  => '是否必填',
            'notice'       => '提示文字',

            'fields.*.field_id'       => '字段key',
            'fields.*.scale_x'        => '横坐标',
            'fields.*.scale_y'        => '纵坐标',
            'fields.*.font_size'      => '字体大小',
        ];
    }
}
